# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=freetype

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.5.3
pkgrel=2
pkgdesc="TrueType font rendering library (mingw-w64)"
arch=('any')
url="http://www.freetype.org/"
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-zlib"
    "${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-bzip2"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-harfbuzz")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip' '!libtool' 'staticlibs')
source=(http://downloads.sourceforge.net/sourceforge/freetype/freetype-${pkgver}.tar.bz2
        freetype-2.2.1-enable-valid.patch
        freetype-2.5.1-enable-spr.patch
        freetype-2.5.1-enable-sph.patch
        mingw-config.patch)
md5sums=('d6b60f06bfc046e43ab2a6cbfd171d65'
         '214119610444c9b02766ccee5e220680'
         '80a14cce234f3f190cd936ca9060c398'
         '0636ba2ff074201e2ea5c47ac408bc63'
         '9d62583e770c59af1c6bd19db89e7cf3')

prepare() {
  cd "${srcdir}/freetype-${pkgver}"
  patch -p1 -i "${srcdir}/freetype-2.2.1-enable-valid.patch"
  patch -p1 -i "${srcdir}/freetype-2.5.1-enable-spr.patch"
  patch -p1 -i "${srcdir}/mingw-config.patch"

  # Disabled for now due to resistance
  # Kept here for easier rebuilds via ABS
  # https://bugs.archlinux.org/task/35274
  #patch -Np1 -i "${srcdir}/freetype-2.5.1-enable-sph.patch"
}

build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"
  CFLAGS+=" $(pkg-config --cflags-only-I harfbuzz freetype2 libpng)"
  CXXFLAGS+=" $(pkg-config --cflags-only-I harfbuzz freetype2 libpng)"
  CPPFLAGS+=" $(pkg-config --cflags-only-I harfbuzz freetype2 libpng)"
  ../freetype-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --enable-shared \
    --with-zlib=${MINGW_PREFIX} \
    --with-bzip2=${MINGW_PREFIX} \
    --with-png=${MINGW_PREFIX} \
    --with-harfbuzz=${MINGW_PREFIX}
  make
}

package () {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install
}
